﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CloudReader.Design
{
    public class ImageMaker
    {
        public static System.IO.MemoryStream Make(int width, int height, int stroke)
        {
            int stride = 4 - (width * 3) % 4;
            int count = (width + stride) * 3 * height;
            byte[] pic = new byte[count + 54];
            var min = width < height ? width : height;

            var r = min / 2;
            var center_x = width / 2;
            var center_y = height / 2;
            int offset = 54;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (!onCircle(x, center_x, y, center_y, r))
                    {
                        pic[offset++] = 0;
                        pic[offset++] = 0;
                        pic[offset++] = 0;
                        //填充黑色透明图层
                    }
                    else
                    {
                        if (stroke != 0)
                        {

                        }
                        else
                        {
                            pic[offset++] = 0;
                            pic[offset++] = 0;
                            pic[offset++] = 0;
                        }
                    }
                    offset += 1;
                }
            }
            return new System.IO.MemoryStream(pic);
        }
        static bool onCircle(int x, int c_x, int y, int c_y, int r)
        {
            //
            var a = x - c_x;
            var b = y - c_y;
            if (Math.Pow(a, 2) + Math.Pow(b, 2) <= r)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
